// 请求头，拦截器
import Axios from "axios";
import store from "../store/index";

const request = Axios.create({
  baseURL: "http://192.168.68.49:8601/",
  // transformResponse: [
  // 	function(data) {
  // 		try {
  // 			return JSONNigint.parse(data)
  // 		} catch (err) {
  // 			return data
  // 		}
  // 	},
  // ],
});

// 请求拦截器
request.interceptors.request.use(
  function(config) {
    // config 本次请求的请求配置对象
    const token = store.state.user;
    if (token && token.token) {
      config.headers.Authorization = `${token.token}`;
    }
    // console.log(token.token)
    // config.headers.Authorization =
    // 	'bearer_eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhZG1pblVpZCI6IjFmMDFjZDFkMmY0NzQ3NDNiMjQxZDc0MDA4YjEyMzMzIiwicm9sZSI6Im51bGzotoXnuqfnrqHnkIYiLCJjcmVhdFRpbWUiOjE2MDcyNTE4OTA1MzksInN1YiI6ImFkbWluIiwiaXNzIjoibW9ndWJsb2ciLCJhdWQiOiIwOThmNmJjZDQ2MjFkMzczY2FkZTRlODMyNjI3YjRmNiIsImV4cCI6MTYwNzI1NTQ5MCwibmJmIjoxNjA3MjUxODkwfQ.urU07KOZvXskroArw-nqAoqIkv-wr4gKVzt1Ft43qhk'
    return config;
  },
  function(error) {
    return Promise.reject(error);
  }
);

// 响应拦截器
request.interceptors.response.use(
  function(response) {
    return response;
  },
  function(error) {
    return Promise.reject(error);
  }
);

export default request;
